package com.cc.service.impl;

import com.cc.mapper.StudentMapper;
import com.cc.pojo.EmpQueryParam;
import com.cc.pojo.PageResult;
import com.cc.pojo.Student;
import com.cc.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public PageResult<Student> list(EmpQueryParam empQueryParam) {
        PageHelper.startPage(empQueryParam.getPage(),empQueryParam.getPageSize());
        List<Student> empList=studentMapper.list(empQueryParam);
        Page<Student> empPage=(Page<Student>) empList;
        return new PageResult<>(empPage.getTotal(),empPage.getResult());

    }

    @Override
    public void delect(List<Integer> ids) {
        studentMapper.delect(ids);
    }

    @Override
    public void add(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.add(student);
    }

    @Override
    public Student getID(Integer id) {
        return studentMapper.getID(id);


    }

    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);

    }

    @Override
    public boolean weiji(Integer id, Integer score) {

        try {
            Map<String,Object> map=new HashMap<>();
            map.put("id",id);
            map.put("score",score);
           int count = studentMapper.weiji(map);
            return count==1;
        } catch (Exception e) {
            throw new RuntimeException(e);

        }




    }
}
